package com.learn.algorithm.graph;

public class Move {
    public static int[] move = new int[]{-1, 0, 1, 0, -1};

    public static void forEachMove(int x, int y, int limitX, int limitY, Moved moved) {
        for (int i = 0; i < 4; i++) {
            int toX = x + move[i];
            int toY = y + move[i + 1];
            if (toX >= 0 && toX < limitX && toY >= 0 && toY < limitY) {
                moved.to(x + move[i], y + move[i + 1]);
            }
        }
    }

    interface Moved {
        void to(int toX, int toY);
    }
}
